package com.zy.design.oop.upFile;

import com.zy.design.oop.upFile.servcie.ImageStore;
import com.zy.design.oop.upFile.servcie.imp.AlyImageStore;
import com.zy.design.oop.upFile.servcie.imp.PrivateImageStore;
import org.checkerframework.checker.units.qual.C;

/**
 * @author zhaoyi
 * @date 2021/2/5 11:03
 */
public class ImageProcessingJob {
    private static final String BUCKET_NAME = "ai_images_bucket";

    public void process(){
        Image image = new Image("小猫");// 处理图片，并封装为 Image 对象
        //果我们要替换图片存储方式，还是需要修改很多类似下面的代码
        //ImageStore imageStore = new PrivateImageStore();
        ImageStore imageStore = new AlyImageStore();
        imageStore.upload(image, BUCKET_NAME);
    }

    /**
     * 更换 ImageStore 实现类需要修改很多
     * 类似 ImageStore imageStore = new AlyImageStore(); 的代码
     * 利用反射+配置文件 减少改动
     * @throws ClassNotFoundException
     */
    public void process2() throws ClassNotFoundException, IllegalAccessException, InstantiationException {
        //假设从配置文件中读取到了 具体使用的类
        Class storeClass = Class.forName("com.zy.design.oop.upFile.servcie.imp.PrivateImageStore");
        ImageStore imageStore = (ImageStore) storeClass.newInstance();

        Image image = new Image("小猫");// 处理图片，并封装为 Image 对象
        imageStore.upload(image, BUCKET_NAME);
    }

    public static void main(String[] args) throws IllegalAccessException, InstantiationException, ClassNotFoundException {
        ImageProcessingJob job = new ImageProcessingJob();
        job.process();
        job.process2();
    }

}



